package grpc

import (
	"base_server/internal/models/store"
	"base_server/internal/models/store_fashion"
	"base_server/internal/models/store_group"
	"context"
	"jihe.common/protos/base_server/proto"
)

func (s *Server) GetStoreByDuid(c context.Context, req *proto.GetStoreByDuidReq) (ret *proto.DStore, err error) {
	ret = new(proto.DStore)
	storeTbl := store.NewModel(s.Pgsql.Get())
	return storeTbl.GetByDuid(req.DUid)
}

func (s *Server) CreateStore(c context.Context, req *proto.DStore) (ret *proto.DStore, err error) {
	ret = new(proto.DStore)
	storeTbl := store.NewModel(s.Pgsql.Get())
	err = storeTbl.Create(req)
	return
}

func (s *Server) CreateStoregroup(c context.Context, req *proto.DStoreGroup) (ret *proto.DStoreGroup, err error) {
	ret = new(proto.DStoreGroup)
	storeGroupTbl := store_group.NewModel(s.Pgsql.Get())
	return storeGroupTbl.Create(req)
}

func (s *Server) GetStoregroupByDuid(c context.Context, req *proto.DStore) (ret *proto.DStore, err error) {

	return
}

func (s *Server) GetStoregroupList(c context.Context, req *proto.GetStoregroupListReq) (ret *proto.DStoreGroups, err error) {
	ret = new(proto.DStoreGroups)
	ret.List, err = store_group.NewModel(s.Pgsql.Get()).GetListByLimit(req.DUid)
	if err != nil {
		return
	}
	return
}

func (s *Server) CreateStoreFashion(c context.Context, req *proto.DStoreFashion) (ret *proto.DStoreFashion, err error) {
	ret = new(proto.DStoreFashion)
	ret, err = store_fashion.NewModel(s.Pgsql.Get()).Create(req)
	if err != nil {
		return
	}
	return
}

func (s *Server) GetStoreGroupFashion(c context.Context, req *proto.GetStoreGroupFashionReq) (ret *proto.DStoreFashions, err error) {
	ret = new(proto.DStoreFashions)
	ret.List, err = store_fashion.NewModel(s.Pgsql.Get()).GetListByLimit(req.GroupId)
	if err != nil {
		return
	}
	return
}
